
(function () { 
	Lhs.ui.CreateManagementWindow = function () {
	var pathimage=Ti.App.Properties.getString('pathimage');
	var platformWidth=Titanium.Platform.displayCaps.platformWidth;//Ti.App.Properties.getInt('platformWidth');
	var platformHeight=Titanium.Platform.displayCaps.platformHeight;//Ti.App.Properties.getInt('platformHeight');
    var win = Titanium.UI.createWindow({
        id: 'Management',
        title: 'Management',
        fullscreen: true,
        backgroundImage: pathimage+'setting.png',
        navBarHidden:true,
        orientationModes:[
	        Titanium.UI.LANDSCAPE_LEFT,
	        Titanium.UI.LANDSCAPE_RIGHT,
		]
      
    });
    /*
    var egc = new globals.EventGarbageCollection(win);
    egc.addEventListener('back_'+win.id, function () {
    	Lhs.navGroup.close(win, {
             animated: true
        });
    	
	});
	*/
	 var tb_Table=Ti.UI.createTableView({
	  	backgroundColor:'Transparent',
	  	separatorColor:'Transparent',
	  	top:30,
	  	bottom:30,
	  	height:400,//platformHeight-(60+Ti.App.Properties.getInt('Order_buttonnumber_height')),
	  	width:platformWidth-50,
	  	touchEnabled: true,
		  	
    })
  //  win.add(tb_Table)
	
	var CreateTableViewRow1 = function(top,width,height) {
		
		var vi= Titanium.UI.createView({
			right:30,
			top:top,
		 	width:width,
			height:height
		}); 
		
		var title = Ti.UI.createLabel({
			text:'Chạy chế độ demo',
			color:'Black',
			left:30,
			font:{
				fontSize:50,
				fontWeight:'bold'
			}
		})
		
		var bt = Titanium.UI.createView({
			right:0,
			//backgroundImage: pathimage+'chk_correct_default.png',
		 
		 	width:height,
			height:height
		}); 
		
		
		bt.addEventListener('click', function (e) {
			//alert(vi_check.backgroundImage)
			require('settings').ClickSound();
			if(bt.backgroundImage==pathimage+'chk_correct_pressed.png')
			{
				e.source.backgroundImage=pathimage+'chk_correct_default.png'
				Ti.App.Properties.setInt('IsDemo', 0);
			}
		    else
		    {
		    	e.source.backgroundImage=pathimage+'chk_correct_pressed.png'
		    	Ti.App.Properties.setInt('IsDemo', 1);
		    }
	    })
	  
		if(Ti.App.Properties.getInt('IsDemo')==0)
		{
			bt.backgroundImage=pathimage+'chk_correct_default.png'
		}
	    else
	    {
	    	bt.backgroundImage=pathimage+'chk_correct_pressed.png'
	    	
	    }
	
		
		var vi_line = Titanium.UI.createView({
			bottom:0,
			width:'100%',
			height:2,
			backgroundImage: pathimage+'img_devide_line_setting.png',
		 	touchEnabled: false,
		}); 
		vi.add(title);
		vi.add(vi_line);
		vi.add(bt);
	
		return vi;
	};
	var CreateTableViewRow2 = function(top,width,height) {
		
		var vi= Titanium.UI.createView({
			right:30,
			top:top,
		
		 	
		 	width:width,
			height:height
		}); 
		
	
		var title = Ti.UI.createLabel({
			text:'Server',
			color:'Black',
			left:30,
			font:{
				fontSize:50,
				fontWeight:'bold'
			}
		})
	
		var txtserver = Titanium.UI.createTextField({
			borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		    keyboardType: Titanium.UI.KEYBOARD_DEFAULT,
		   // returnKeyType: Titanium.UI.RETURNKEY_SEARCH , 
			textAlign:'left',
			hintText:'Địa chỉ server',
			right:0,
			
			height:height,
			width:platformWidth-300,
		 	font:{
				fontSize:30,
				fontWeight:'bold',
			 },
		}); 
	
		txtserver.value=Ti.App.Properties.getString('Server')
		
		txtserver.addEventListener('return', function(e)
		{
		
			txtserver.blur();
			Ti.App.Properties.setString('Server',txtserver.value);
			
		});
		
		
		
		var vi_line = Titanium.UI.createView({
			bottom:0,
			width:'100%',
			height:2,
			backgroundImage: pathimage+'img_devide_line_setting.png',
		 	touchEnabled: false,
		}); 
		vi.add(title);
		vi.add(vi_line);
		vi.add(txtserver);
		
		return vi;
	};
	var LoadTables = function() {
	
		row1=CreateTableViewRow1(30,platformWidth-50,90)
		win.add(row1)
		row2=CreateTableViewRow2(30+row1.height,platformWidth-50,90)
		win.add(row2)
	
	
	
		
	    
	    
	    
	};
	
	
	var btClose = Titanium.UI.createButton({
		 borderColor: '#c0c0c0',
		 borderRadius: 5,
		 borderWidth:2,
		 color:'Black',
		 title:'Đóng',
		 bottom:30,
		 right:30,
		 backgroundImage:pathimage+'bt_red.png',
		 backgroundSelectedImage:pathimage+'bt_red_press.png',
		 width:150,
		 height:Ti.App.Properties.getInt('Order_buttonnumber_height'),
		 font:{
				//fontSize:Ti.App.Properties.getInt('MainWindow_btnumber_fontsize'),
				fontWeight:'bold',
		 },
   	 	 
	}); 
	btClose.addEventListener('click', function (e) {
		//Ti.API.info(e.source.parent.c)
		//Ti.App.Properties.setString('Server',txtserver.value);
		Lhs.navGroup.close(win, {
             animated: true
        });
    })
	win.add(btClose)
	
	
	/////////////EVEN/////////////////////////
	win.addEventListener('open', function (e) {
		
		 LoadTables()
	});
	// removing the event listener does
	win.addEventListener('close', function() {
		//Ti.App.removeEventListener('bad:idea');
	});
	
	
 	return win;
       
    };
})();